package com.ruoyi.backstage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zzw.domain.SafenessIndex;
import com.ruoyi.zzw.service.TSafenessIndexService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 平安指数管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/backstage/safeness")
public class BackSafenessIndexController extends BaseController
{
    @Autowired
    private TSafenessIndexService tSafenessIndexService;

    /**
     * 查询平安指数管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:safeness:list')")
    @GetMapping("/list")
    public AjaxResult list(SafenessIndex safenessIndex)
    {
        startPage();
        List<SafenessIndex> list = tSafenessIndexService.selectTSafenessIndexList(safenessIndex);
        return success(list);
    }

    /**
     * 导出平安指数管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:safeness:export')")
    @Log(title = "平安指数管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafenessIndex safenessIndex)
    {
        List<SafenessIndex> list = tSafenessIndexService.selectTSafenessIndexList(safenessIndex);
        ExcelUtil<SafenessIndex> util = new ExcelUtil<SafenessIndex>(SafenessIndex.class);
        util.exportExcel(response, list, "平安指数管理数据");
    }

    /**
     * 获取平安指数管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:safeness:query')")
    @GetMapping(value = "/{cSafenessId}")
    public AjaxResult getInfo(@PathVariable("cSafenessId") Long cSafenessId)
    {
        return success(tSafenessIndexService.selectTSafenessIndexByCSafenessId(cSafenessId));
    }

    /**
     * 新增平安指数管理
     */
    @PreAuthorize("@ss.hasPermi('system:safeness:add')")
    @Log(title = "平安指数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafenessIndex safenessIndex)
    {
        return toAjax(tSafenessIndexService.insertTSafenessIndex(safenessIndex));
    }

    /**
     * 修改平安指数管理
     */
    @PreAuthorize("@ss.hasPermi('system:safeness:edit')")
    @Log(title = "平安指数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafenessIndex safenessIndex)
    {
        return toAjax(tSafenessIndexService.updateTSafenessIndex(safenessIndex));
    }

    /**
     * 删除平安指数管理
     */
    @PreAuthorize("@ss.hasPermi('system:safeness:remove')")
    @Log(title = "平安指数管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cSafenessIds}")
    public AjaxResult remove(@PathVariable Long[] cSafenessIds)
    {
        return toAjax(tSafenessIndexService.deleteTSafenessIndexByCSafenessIds(cSafenessIds));
    }
}
